package game.ui.data
{
	import flash.events.*;
	import game.ui.events.*;
	
	public class RxArrayCollection extends EventDispatcher implements RxIDataCollection
	{
		private var m_source:Object;
		
		public function RxArrayCollection(param1:* = null)
		{
			if (!param1)
			{
				this.m_source = [];
			}
			else
			{
				this.m_source = param1;
			}
		}
		
		public function SetSource(param1:*) : void
		{
			this.m_source = param1;
		}
		
		public function AddItemsFromArray(param1:*) : void
		{
			var _loc_2:Object = null;
			if (!this.m_source)
			{
				this.SetSource(param1);
			}
			else
			{
				for each (_loc_2 in param1)
				{
					
					this.m_source.push(_loc_2);
				}
			}
		}
		
		public function GetItemAt(param1:int) : Object
		{
			return this.m_source[param1];
		}
		
		public function RemoveItemAt(param1:int) : Object
		{
			var _loc_3:RxDataProviderEvent = null;
			if (param1 >= this.m_source.length || param1 < 0)
			{
				return null;
			}
			var _loc_2:* = this.m_source.splice(param1, 1);
			if (hasEventListener(RxDataProviderEvent.ITEM_REMOVED))
			{
				_loc_3 = new RxDataProviderEvent(RxDataProviderEvent.ITEM_REMOVED);
				_loc_3.data = _loc_2;
				_loc_3.index = param1;
				dispatchEvent(_loc_3);
			}
			return _loc_2;
		}
		
		public function SwapItemsAt(param1:int, param2:int) : void
		{

		}
		
		public function ReplaceItemAt(param1:int, param2:Object) : void
		{
			var _loc_4:RxDataProviderEvent = null;
			var _loc_3:* = this.m_source[param1];
			this.m_source[param1] = param2;
			if (hasEventListener(RxDataProviderEvent.ITEM_REPLACED))
			{
				_loc_4 = new RxDataProviderEvent(RxDataProviderEvent.ITEM_REPLACED);
				_loc_4.data = param2;
				_loc_4.oldData = _loc_3;
				_loc_4.index = param1;
				dispatchEvent(_loc_4);
			}
		}
		
		public function GetLength() : int
		{
			return this.m_source.length;
		}
		
		public function AddItem(param1:Object) : void
		{
			var _loc_2:RxDataProviderEvent = null;
			this.m_source.push(param1);
			if (hasEventListener(RxDataProviderEvent.ITEM_ADDED))
			{
				_loc_2 = new RxDataProviderEvent(RxDataProviderEvent.ITEM_ADDED);
				_loc_2.data = param1;
				_loc_2.index = this.m_source.length - 1;
				dispatchEvent(_loc_2);
			}
		}
		
		public function AddItemAt(param1:Object, param2:int) : void
		{
			var _loc_3:RxDataProviderEvent = null;
			this.m_source.splice(param2, 0, param1);
			if (hasEventListener(RxDataProviderEvent.ITEM_ADDED))
			{
				_loc_3 = new RxDataProviderEvent(RxDataProviderEvent.ITEM_REMOVED);
				_loc_3.data = param1;
				_loc_3.index = param2;
				dispatchEvent(_loc_3);
			}
		}
		
		public function RemoveAll() : void
		{
			this.m_source = [];
		}
		
		public function GetIndexOfItem(param1:Object) : int
		{
			if (!this.m_source)
			{
				return -1;
			}
			return this.m_source.indexOf(param1);
		}
		
	}
}
